package chapter6.meine;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JApplet;
import javax.swing.JPanel;

public class DrawRectsOnMouseClick extends JApplet{
	
	private class DrawRectPanel extends JPanel{
		
		public void paintComponent(Graphics g) {
			super.paintComponent(g);
			setBackground(Color.black);
			
		} // end of paintComponent ()
					
	}// end of class DrawRectPanel
	
	public class MListener implements MouseListener {

		@Override
		public void mouseClicked(MouseEvent e) {
			Graphics g = getGraphics();
			
			if (e.isMetaDown()){
			g.setColor(Color.BLUE);
			int x = e.getX();
			int y = e.getY();
			g.fillOval(x, y, 30, 20);
			}
			else if (e.isShiftDown()){
				repaint();
			}
			else {
				g.setColor(Color.RED);
				int x = e.getX();
				int y = e.getY();
				g.fillRect(x, y, 30, 20);
				
			}
					
			// TODO Auto-generated method stub
			
		}

		@Override
		public void mouseEntered(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void mouseExited(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void mousePressed(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void mouseReleased(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}
		
	}
	
	 public void init() {
		    
		 DrawRectPanel content = new DrawRectPanel();
	     setContentPane(content);
	     addMouseListener(new MListener());
	   }

}// end of class DrawRectsOnMouseClick


